<?php
class IndexAction extends CommonAction  {

	
	
	public function Index(){
	
	import('ORG.Util.Page');// 导入分页类
	$Data = M('user');
	$count      = $Data->where($map)->count();// 查询满足要求的总记录数 $map表示查询条件
    $Page       = new Page($count);// 实例化分页类 传入总记录数
    $show       = $Page->show();// 分页显示输出
    // 进行分页数据查询
    $list = $Data->where($map)->order('id')->limit($Page->firstRow.','.$Page->listRows)->select();
    
    
	

	$this->assign('list',$list);// 赋值数据集
    $this->assign('page',$show);// 赋值分页输出
	$this->display();
	}
	

	

	
	
	
	public function logout(){
		session(null);
		
		$this->success("退出成功");
	} 
	
	public function pushexcel(){
	$user=m("user");
	$list=$user->select();
	Vendor("Classes.PHPExcel");
	Vendor("Classes.PHPExcel.IOFactory");
	Vendor("Classes.PHPExcel.Reader.Excel5");
	//创建处理对象实例
	$objPhpExcel=new PHPExcel();
	$objPhpExcel->getActiveSheet()->getDefaultColumnDimension()->setAutoSize(true);//设置单元格宽度
	//设置表格的宽度  手动
	$objPhpExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
	$objPhpExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
	$objPhpExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
	$objPhpExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
	//设置标题
	$rowVal = array(0=>'编号',1=>'姓名', 2=>'手机号码', 3=>'详细地址', 4=>'参与时间');
	foreach ($rowVal as $k=>$r){
	$objPhpExcel->getActiveSheet()->getStyleByColumnAndRow($k,1)
	->getFont()->setBold(true);//字体加粗
	$objPhpExcel->getActiveSheet()->getStyleByColumnAndRow($k,1)->
	getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);//文字居中
	$objPhpExcel->getActiveSheet()->setCellValueByColumnAndRow($k,1,$r);
	}
	//设置当前的sheet索引 用于后续内容操作
	$objPhpExcel->setActiveSheetIndex(0);
	$objActSheet=$objPhpExcel->getActiveSheet();
	//设置当前活动的sheet的名称
	$title="参与人员";
	$objActSheet->setTitle($title);
	//设置单元格内容
	foreach($list as $k => $v)
	{
		$v['times'] = date('Y-m-d H:i:s');
	$num=$k+2;
	$objPhpExcel->setActiveSheetIndex(0)
	//Excel的第A列，uid是你查出数组的键值，下面以此类推
	->setCellValue('A'.$num, $v['id'])
	->setCellValue('B'.$num, $v['username'])
	->setCellValue('C'.$num, $v['mobil'])
	->setCellValue('D'.$num, $v['address'])
	->setCellValue('E'.$num, $v['times']);

	}
	$name=date('Y-m-d');//设置文件名
	header("Content-Type: application/force-download");
	header("Content-Type: application/octet-stream");
	header("Content-Type: application/download");
	header("Content-Transfer-Encoding:utf-8");
	header("Pragma: no-cache");
	header('Content-Type: application/vnd.ms-excel');
	header('Content-Disposition: attachment;filename="'.$title.'_'.urlencode($name).'.xls"');
	header('Cache-Control: max-age=0');
	$objWriter = PHPExcel_IOFactory::createWriter($objPhpExcel, 'Excel5');
	$objWriter->save('php://output');
	}
	
} 